jQuery(function($){
    $.use("search.waterfall",function(){
        var waterfall = $.wanjuhe.waterfall(),
            wjh_waterfall = waterfall.wjh_waterfall,
            waterfall_contenter = waterfall.waterfall_contenter,
            loading = waterfall.loading,
            key=1,page=1;
        $(window).scroll(function(){
            if((waterfall_contenter.offset().top+waterfall_contenter.outerHeight()-$(window).scrollTop()) < $(window).height() && key){
                key=0;
                loading.show();
                $.ajax({
                        "url": "ajax/list.php",
                        "type": "GET",
                        "dataType" : 'json',
                        "success":function(data){
                            if(data.state === "sucess"){
                                page++;
                                var JsonDataCache=[];
                                if(page % 4 == 0){$(".wjh-list").html('');wjh_waterfall.clearBefore();$(window).scrollTop(0);};
                                $(data.items).each(function(index,value){
                                    var v = $(value),contenter = $('#J_waterfall-contenter .wjh-list');
                                    if(contenter.length == 0){
                                        contenter = $('#J_waterfall-contenter');
                                    }
                                    v.css({"top":wjh_waterfall.cssHeight[0]+'px',"left":wjh_waterfall.cssWidth[0]+'px'}).appendTo(contenter);
                                    JsonDataCache.push(v);
                                });
                                wjh_waterfall.adjustPosition(JsonDataCache);
                                key=1;
                                loading.hide();
                            }
                        },
                        "timeout" : 20000,
                        "error" : function(){
                        }
                    }
                );
            };
        });
    });
});